<?php
/**
 * <https://y.st./>
 * Copyright © 2017 Alex Yst <mailto:copyright@y.st>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org./licenses/>.
**/

$xhtml = array(
	'title' => '<code>package payrollsystem;</code>',
	'subtitle' => 'Written in <span title="Programming 1">CS 1102</span> of <a href="http://www.uopeople.edu/">University of the People</a>, finalised on <del>2017-05-10</del> <del><ins>2017-05-17</ins></del> <ins>2017-05-24</ins>',
	'copyright year' => '2017',
	'body' => <<<END
<h2>Employee.java</h2>
<blockquote>
<pre><code>/*
 * Copyright (C) 2017 Alex Yst
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
package payrollsystem;

/**
 * An abstract class for representing employee pay information
 * 
 * @author Alex Yst
 */
public abstract class Employee {
	private int empID;
	private String name;
	private Vehicle vehicle;
/**
 * @return the empID
 */
	public int getEmpID() {
		return empID;
	}
/**
 * @param empID the empID to set
 */
	public void setEmpID(int empID) {
		this.empID = empID;
	}
/**
 * @return the name
 */
	public String getName() {
		return name;
	}
/**
 * @param name the name to set
 */
	public void setName(String name) {
		this.name = name;
	}
/**
 * @return the vehicle
 */
	public Vehicle getVehicle() {
		return vehicle;
	}
/**
 * @param vehicle the vehicle to set
 */
	public void setVehicle(Vehicle vehicle) {
		this.vehicle = vehicle;
	}
/**
 * A bare constructor method. Not used by the program.
 */
	public Employee() {
		this.empID = 0;
		this.name = &quot;&quot;;
	}
/**
 * Constructor method. This is the only one of the three constructor methods
 * actually used by the program.
 * 
 * @param pEmpID The employee&apos;s ID number
 * @param pName The employee&apos;s name
 * @param pV An object representing the employee&apos;s vehicle, if any
 */
	public Employee(int pEmpID, String pName, Vehicle pV) {
		this.empID = pEmpID;
		this.name = pName;
		this.vehicle = pV;
	}
/**
 * The most comprehensive constructor method of this class. Not used by the
 * program
 * 
 * @param pEmpID The ID number of the employee
 * @param pName The name of the employee
 * @param pPlate The registration plate number of the employee&apos;s vehicle
 * @param pColour The colour of the employee&apos;s vehicle
 */
	public Employee(int pEmpID, String pName, String pPlate, String pColour) {
		this.empID = pEmpID;
		this.name = pName;
		this.vehicle = new Vehicle(pPlate, pColour);
	}
/**
 * The rules for determining an employee&apos;s pay are determined by what type of
 * employee they are. This method must be defined in child classes.
 * 
 * @return The calculated pay
 */
	public abstract double calculatePay();
}</code></pre>
</blockquote>
<h2>FullTime.java</h2>
<blockquote>
<pre><code>/*
 * Copyright (C) 2017 Alex Yst
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
package payrollsystem;

/**
 * A class for representing full-time employees
 * 
 * @author Alex Yst
 */
public class FullTime extends Employee {
	private double salary;
	private double overtime;
/**
 * Calculates the ammount that sould be paid to the employee
 * 
 * @return The ammout of pay due to the employee
 */
@Override
	public double calculatePay() {
		System.out.println(&quot;Full time employee.&quot;);
		return this.getSalary() + this.getOvertime();
	}
/**
 * @return the salary
 */
	public double getSalary() {
		return salary;
	}
/**
 * @param salary the salary to set
 */
	public void setSalary(double salary) {
		this.salary = salary;
	}
/**
 * @return the overtime
 */
	public double getOvertime() {
		return overtime;
	}
/**
 * @param overtime the overtime to set
 */
	public void setOvertime(double overtime) {
		this.overtime = overtime;
	}
/**
 * Constructor method
 * 
 * @param id The ID number of the employee
 * @param name The name of the employee
 * @param sal The salary of the employee
 * @param hourAndHalf unclear - might be overtime pay or might be employee bonus
 * @param vehicle an object representing the employee&apos;s vehicle, if any
 */
	public FullTime(int id, String name, double sal, double hourAndHalf, Vehicle vehicle) {
		super(id, name, vehicle);
		this.overtime = hourAndHalf;
		this.salary = sal;
	}
}</code></pre>
</blockquote>
<h2>PartTime.java</h2>
<blockquote>
<pre><code>/*
 * Copyright (C) 2017 Alex Yst
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
package payrollsystem;

/**
 * A class for representing part-time employees
 * 
 * @author Alex Yst
 */
public class PartTime extends Employee {
	private double rate;
	private double hoursWorked;
/**
 * Calculates the ammount that sould be paid to the employee
 * 
 * @return The ammout of pay due to the employee
 */
	@Override
	public double calculatePay() {
		System.out.println(&quot;Part time employee.&quot;);
		return this.getHoursWorked() * this.getRate();
	}
/**
 * @return the rate
 */
	public double getRate() {
		return rate;
	}
/**
 * @param rate the rate to set
 */
	public void setRate(double rate) {
		this.rate = rate;
	}
/**
 * @return the hoursWorked
 */
	public double getHoursWorked() {
		return hoursWorked;
	}
/**
 * @param hoursWorked the hoursWorked to set
 */
	public void setHoursWorked(double hoursWorked) {
		this.hoursWorked = hoursWorked;
	}
/**
 * Constructor method
 * 
 * @param id The ID number of the employee
 * @param name The name of the employee
 * @param rate The hourly rate of the employee
 * @param hoursWorked2 The number of hours the employee has worked
 * @param v1 An object representing the vehicle of the employee
 */
	public PartTime(int id, String name, double rate, double hoursWorked2, Vehicle v1) {
		super(id, name, v1);
		this.rate = rate;
		this.hoursWorked = hoursWorked2;
	}
}</code></pre>
</blockquote>
<h2>PayrollSystem.java</h2>
<blockquote>
<pre><code>/*
 * Copyright (C) 2017 Alex Yst
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
package payrollsystem;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * A simple program for calculating employee pay
 * 
 * This program facilitates the entering of employee pay information, then adds
 * it up to show the total amount paid to employees by the company. Information
 * on employee vehicles can also be entered, but because the program doesn&apos;t
 * store any information in a database and this program doesn&apos;t use the vehicle
 * information in any way besides simply desplaying it with the employee&apos;s pay,
 * entering that information has no significant benefit.
 * 
 * @author Alex Yst
 */
public class PayrollSystem {
/**
 * This method simply runs the main program.
 * 
 * @param arguments Not implemented
 */
	public static void main(String[] arguments) {
		ArrayList&lt;Employee&gt; arrEmp = new ArrayList&lt;&gt;();
		String varCont = &quot;N&quot;;
		byte menuOption;
		do {
			menuOption = showMenu();
			switch(menuOption) {
				case 1:
					addEmployee(arrEmp, readNewFullTime());
					break;
				case 2:
					addEmployee(arrEmp, readNewPartTime());
					break;
				case 3:
					calcPayroll(arrEmp);
					break;
				default:
					break;
			}
		} while(menuOption != 4);
	}
/**
 * This method promps the user for an employee&apos;s information and generates an
 * object based on that information to represent the employee.
 * 
 * @return An object representing the full-time employee
 */
	public static FullTime readNewFullTime() {
		Scanner kbd = new Scanner(System.in);
		System.out.print(&quot;Enter Id: &quot;);
		int id = kbd.nextInt();
		System.out.print(&quot;\nEnter Name: &quot;);
		String name = kbd.next();
		System.out.print(&quot;\nEnter Salary: &quot;);
		double sal = kbd.nextDouble();
		System.out.print(&quot;\nEnter Bonus: &quot;);
		double hourAndHalf = kbd.nextDouble();
		return new FullTime(id, name, sal, hourAndHalf, getVehicle());
	}
/**
 * This method promps the user for an employee&apos;s information and generates an
 * object based on that information to represent the employee.
 * 
 * @return An object representing the part-time employee
 */
	public static PartTime readNewPartTime() {
		Scanner kbd = new Scanner(System.in);
		System.out.print(&quot;Enter Id: &quot;);
		int id = kbd.nextInt();
		System.out.print(&quot;\nEnter Name: &quot;);
		String name = kbd.next();
		System.out.print(&quot;\nEnter Hourly Rate: &quot;);
		double rate = kbd.nextDouble();
		System.out.print(&quot;\nEnter Number of Hours Worked: &quot;);
		double hoursWorked = kbd.nextDouble();
		return new PartTime(id, name, rate, hoursWorked, getVehicle());
	}
/**
 * This one-line method takes an employee list and an employee, and add the
 * employee to the list. On first glance, it doesn&apos;t seem like a useful method,
 * but it actually provides a layer of abstraction. In the future, employee
 * lists or employee representations may be implemented another way. If and
 * when that happens, this method can be updated instead of updating every
 * instance of adding an employee to a dist throught the code.
 * 
 * @param pArrEmp The list of employees
 * @param pEmp The employee to add to the list
 */
	public static void addEmployee(ArrayList&lt;Employee&gt; pArrEmp, Employee pEmp) {
		pArrEmp.add(pEmp);
	}
/**
 * This method shows the user the options and returns their input. Why is our
 * menu indexed from one instead of zero? Are we common fools that don&apos;t
 * understand zero comes before one!?
 * 
 * @return A byte specified by the user
 */
	public static byte showMenu() {
		Scanner kbd = new Scanner(System.in);
		System.out.println(&quot;/* *********************************************************/&quot;);
		System.out.println(&quot;/* 1. Add FullTime                                         */&quot;);
		System.out.println(&quot;/* 2. Add PartTime                                         */&quot;);
		System.out.println(&quot;/* 3. Calculate Payroll                                    */&quot;);
		System.out.println(&quot;/* 4. Exit                                                 */&quot;);
		System.out.println(&quot;/* *********************************************************/&quot;);
		System.out.print(&quot;Input: &quot;);
		return kbd.nextByte();
	}
/**
 * This method displays vehicle information of every employee and, more
 * importantly, calculates every employee&apos;s pay and adds the pay of all
 * employees up to show the total paid out by the company. This should be the
 * final option specified by the user before exiting the program, at least if
 * the user knows what they&apos;re doing.
 * 
 * @param pArrEmp A list of employees
 */
	public static void calcPayroll(ArrayList&lt;Employee&gt; pArrEmp) {
		double totalCompanyPay = 0.0;
		double individualPay;
		for(int i=0; i&lt;pArrEmp.size(); i++) {
			Employee emp = pArrEmp.get(i);
			System.out.println(&quot;\n**************************\n&quot;);
			individualPay = emp.calculatePay();
			Vehicle v = emp.getVehicle();
			String hasVehicle;
			if(v == null) {
				hasVehicle = &quot;No&quot;;
			} else {
				hasVehicle = &quot;Yes&quot;;
			}
			System.out.print(&quot;Employee Name: &quot;);
			System.out.println(emp.getName());
			System.out.print(&quot;Has Vehicle: &quot;);
			System.out.println(hasVehicle);
			if(v != null) {
				System.out.print(&quot;Plate Number: &quot;);
				System.out.println(v.getPlateNumber());
				System.out.print(&quot;Colour: &quot;);
				System.out.println(v.getColour());
			}
			System.out.print(&quot;Take Home Pay: &quot;);
			System.out.println(individualPay);
			totalCompanyPay += individualPay;
		}
		System.out.print(&quot;------------------\nTotal paroll of the company: &quot;);
		System.out.println(totalCompanyPay);
		System.out.println(&quot;------------------&quot;);
	}
/**
 * This method promps the user for information regarding the employee&apos;s
 * vehicle. However, this information is actually useless for calculating
 * payrool and isn&apos;t stored in any database. Therefore, each pay period, the
 * vehicle information must be uselessly re-entered. A smart user of this
 * progran will simply type &quot;N&quot; when asked if the employee has a vehicle to
 * avoid having to look up the employee&apos;s registration plate number and vehicle
 * colour.
 * 
 * @return An object representing the employee&apos;s vehicle
 */
	public static Vehicle getVehicle() {
		Scanner kbd = new Scanner(System.in);
		System.out.print(&quot;\nDoes this employee have a vehicle? Y/N :\nInput : &quot;);
		String hasVehicle = kbd.next();
		if(hasVehicle.equalsIgnoreCase(&quot;Y&quot;)) {
			System.out.print(&quot;\nEnter plate number: &quot;);
			String auxPlate = kbd.next();
			System.out.print(&quot;\nEnter vehicle colour: &quot;);
			String auxColour = kbd.next();
			return new Vehicle(auxPlate, auxColour);
		} else {
			return null;
		}
	}
}</code></pre>
</blockquote>
<h2>Vehicle.java</h2>
<blockquote>
<pre><code>/*
 * Copyright (C) 2017 Alex Yst
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
 */
package payrollsystem;

/**
 * A class for representing employee vehicles
 * 
 * @author Alex Yst
 */
public class Vehicle {
	private String plateNumber;
	private String colour;
/**
 * Constructor method
 * 
 * @param plateNumber The registration plate number of the vehicle
 * @param colour The colour of the vehicle
 */
	public Vehicle(String plateNumber, String colour) {
		this.plateNumber = plateNumber;
		this.colour = colour;
	}
/**
 * @return the plateNumber
 */
	public String getPlateNumber() {
		return plateNumber;
	}
/**
 * @param plateNumber the plateNumber to set
 */
	public void setPlateNumber(String plateNumber) {
		this.plateNumber = plateNumber;
	}
/**
 * @return the colour
 */
	public String getColour() {
		return colour;
	}
/**
 * @param colour the colour to set
 */
	public void setColour(String colour) {
		this.colour = colour;
	}
}</code></pre>
</blockquote>
END
);
